package com.xhwl.logistics.bo;

import com.xhwl.logistics.util.AboutDateUtil;
import lombok.Getter;
import lombok.Setter;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

@Setter
@Getter
public class VehiclePayRecordStatisticsBO {

    private void initAboutDay(Date startTime, Date endTime) {
        pay = new ArrayList<>();
        for (Date start=startTime; start.before(endTime); start=AboutDateUtil.datePlusDay(start, 1)) {
            VehiclePayRecordStatisticsDateBO vehiclePayRecordStatisticsDateBO = new VehiclePayRecordStatisticsDateBO();
            vehiclePayRecordStatisticsDateBO.setCount(0);
            vehiclePayRecordStatisticsDateBO.setDate(AboutDateUtil.dateToString(start, "yyyy-MM-dd"));
            pay.add(vehiclePayRecordStatisticsDateBO);
        }
    }

    private void initAboutMonth(Date startTime, Date endTime) {
        pay = new ArrayList<>();
        for (Date start=startTime; start.before(endTime); start=AboutDateUtil.datePlusMonth(start, 1)) {
            VehiclePayRecordStatisticsDateBO vehiclePayRecordStatisticsDateBO = new VehiclePayRecordStatisticsDateBO();
            vehiclePayRecordStatisticsDateBO.setCount(0);
            vehiclePayRecordStatisticsDateBO.setDate(AboutDateUtil.dateToString(start, "yyyy-MM"));
            pay.add(vehiclePayRecordStatisticsDateBO);
        }
    }

    /**
     * 按季度分组
     */
    private void initAboutQuarter() {
        pay = new ArrayList<>();
        for (int i = 1; i <= 4; i++) {
            VehiclePayRecordStatisticsDateBO vehiclePayRecordStatisticsDateBO = new VehiclePayRecordStatisticsDateBO();
            vehiclePayRecordStatisticsDateBO.setCount(0);
            vehiclePayRecordStatisticsDateBO.setDate(String.valueOf(i));
            pay.add(vehiclePayRecordStatisticsDateBO);
        }
    }

    public VehiclePayRecordStatisticsBO(Integer type, Date startTime, Date endTime) {
        //这里条件判断可以需要优化一下
        if (type.equals(1)) {
            initAboutDay(startTime, endTime);
        } else if (type.equals(2)) {
            initAboutDay(startTime, endTime);
        } else if (type.equals(3)) {
            initAboutMonth(startTime, endTime);
        } else if (type.equals(4)) {
            initAboutDay(startTime, endTime);
        } else if (type.equals(5)) {
            initAboutDay(startTime, endTime);
        } else if(type.equals(6)) {
            initAboutQuarter();
        } else if (type.equals(7)) {
            initAboutMonth(startTime, endTime);
        } else {
            throw new IllegalArgumentException("缴费记录统计的type值非法，无法完成显示数据的转换");
        }
    }

    private String parkingLotName;

    private List<VehiclePayRecordStatisticsDateBO> pay;

}
